from scipy.stats import pearsonr
from scipy.stats import linregress
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
from scipy import sparse


def point_inverse(src_array,height,width):
    sparse_arr = sparse.coo_matrix((src_array[:,2],(src_array[:,0],src_array[:,1])),shape=(height,width))
    dst_arr = sparse_arr.toarray()
    return dst_arr

def calc_regression_metric(y_true, y_pred):
    return {
        "COUNT": len(y_true),
        "RMSE": mean_squared_error(y_true, y_pred) ** 0.5,
        "MAE": mean_absolute_error(y_true, y_pred),
        "R2": linregress(y_true, y_pred).rvalue**2,
        "PEARSON": pearsonr(y_true, y_pred)[0]
    }